package com.digital.welcome.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.digital.welcome.entity.User;
import com.digital.welcome.entity.UserCheckIn;
import com.digital.welcome.mapper.UserCheckInMapper;
import com.digital.welcome.response.Result;
import com.digital.welcome.service.UserCheckInService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 莲童的雨儿
 */
@Service
public class UserCheckInServiceImpl extends ServiceImpl<UserCheckInMapper, UserCheckIn> implements UserCheckInService {
    @Autowired
    private UserCheckInMapper userCheckInMapper;

    @Override
    public Boolean selectState(String userName) {
        QueryWrapper<UserCheckIn> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_name", userName);
        Integer count = userCheckInMapper.selectCount(queryWrapper);
        return count != 0;
    }

    @Override
    public String userCheckInDo(User user) {
        if (user == null || user.getUserName() == null) {
            return JSON.toJSONString(new Result<>().setCode(0).setMessage("用户名为空"));
        }
        UserCheckIn userCheckIn = new UserCheckIn();
        userCheckIn.setUserName(user.getUserName());
        userCheckInMapper.insert(userCheckIn);
        return JSON.toJSONString(new Result<>().setCode(1).setMessage("入住办理成功"));
    }
}
